package com.github.yoojia.flow.support;

import com.github.yoojia.flow.Event;
import com.github.yoojia.flow.Payload;

import java.util.Random;

/**
 * @author 陈小锅 (yoojiachen@gmail.com)
 * @since 1.0.0
 */
public class RndIntScheduleDevice extends VirtualScheduleDevice {

    private final Random mRandom = new Random();

    @Override
    protected void onScheduleTask() {
        getContext().publishEvent(
                Event.createNoneDestAddress(
                        0,
                        nextIntBytes(),
                        TOPIC,
                        getAddress(),
                        System.currentTimeMillis()));
    }

    private byte[] nextIntBytes() {
        return Payload.Int.create(mRandom.nextInt(1000)).getBytes();
    }
}
